package com.s10.ecloud.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.s10.ecloud.web.model.User;
import com.s10.ecloud.web.service.IUserService;

@ParentPackage("json-default")
public class C000001Action extends ActionSupport {

	@Resource
	private IUserService userService = null;

	@Action(value = "/checkUserName", results = { @Result(name = "success", params = {
			"root", "result" }, type = "json") })
	public String checkUserName() throws Exception {

		int count = userService.getUserCountByEmail(this.getEmail());
		if (count == 0) {
			this.setResult("0");
		} else {
			this.setResult("1");
		}

		return this.SUCCESS;
	}

	/**
	 * 检查工商登记号是否唯一
	 * 
	 * @return 0：唯一，1.不唯一
	 * @throws Exception
	 */
	@Action(value = "/checkCommerceNo", results = { @Result(name = "success", params = {
			"root", "result" }, type = "json") })
	public String checkCommerceNo() throws Exception {

		List<User> user = userService.getEntUserByCommerceNo(this
				.getCommerceNo());
		if (user.size() == 0) {
			this.setResult("0");
		} else {
			this.setResult("1");
		}

		return this.SUCCESS;
	}

	private String result;
	private String commerceNo;

	/**
	 * @return the commerceNo
	 */
	public String getCommerceNo() {
		return commerceNo;
	}

	/**
	 * @param commerceNo
	 *            the commerceNo to set
	 */
	public void setCommerceNo(String commerceNo) {
		this.commerceNo = commerceNo;
	}

	/**
	 * @return the result
	 */
	public String getResult() {
		return result;
	}

	/**
	 * @param result
	 *            the result to set
	 */
	public void setResult(String result) {
		this.result = result;
	}

	private String email;

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

}
